package core

class GovernorateController {

    def index() { 
		
		
		def max = params.long('max')?:10
 
		def start = params.long('start')?:1
 
		 [governorates: Governorate.list(max: max, offset:start ),max:max, start:start ]
 
	}
	def create() {
		
	}
 
	def show() {
 
		[governorate: Governorate.get(params.long('id'))]
 
	}
 
	def save(){
 

 
		def governorate = new Governorate(params)
 
		if (governorate.save()) {
 
			flash.notice = "Governorate: ${governorate.name} was saved"
 
			redirect(action: 'index')
 
		}
 
		else {
 
			flash.error = "Governorate: ${governorate.name} failed to be saved"
 
			render(view:'create', model:[governorate: Governorate])
 
		}
 
	}
 

 
	//================================================================================
 
	def update() {
 
		def governorate =  Governorate.get(params.long('id'))
 
		governorate.properties = params
 
		if(governorate.save()) {
 
			flash.notice = "Governorate: ${governorate.name} was updated"
 
			redirect action:'index'
 
		}
 
		else {
 
			flash.error = "Governorate:  failed to be update"
 
			render(view:'edit',model:[governorate: Governorate])
 
		}
 
	}
 

 
	def delete(){
 

 
		def gov = Governorate.get(params.id)
 
		gov.delete()
 
		redirect(action:"index")
 
	}
 

 
	def edit(){
 

 
		[governorate: Governorate.get(params.long('id'))]
 

 

 
	}
}
